using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;
public partial class Admin_LoaiSPList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        PagerV2_8_1.PageSize = 5;
        Criteria cri = new Criteria();
        int Total = 0;
        if (txt_TenLoai.Text != "")
        {
            cri.add(Condition.AND, tbLoaiSPColumns.TenLoai.ToString(), Condition.LIKE, txt_TenLoai.Text);
        }
       //PagerV2_8_1 .PageSize =int.Parse (ConfigurationManager.AppSettings ["pagesize"].ToString ());
        tbLoaiSPCollection loaispcolection= tbLoaiSPBUS .Get  (cri .Criter ,PagerV2_8_1 .CurrentIndex ,
                                                           PagerV2_8_1 .PageSize  ,tbLoaiSPColumns .IdLoaiSP   .ToString (),
                                                           OrderDirection .ASC .ToString (),out Total );
        Repeater1 .DataSource =loaispcolection ;
        Repeater1.DataBind();
        PagerV2_8_1.ItemCount = Total;
        if (Total <= PagerV2_8_1.PageSize)
            PagerV2_8_1.Visible = false;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {

            Literal hyp_TenLoai = (Literal)e.Item.FindControl("hyp_TenLoai");
            Literal lit_Ma = (Literal)e.Item.FindControl("lit_Ma");
            HyperLink hyp_Edit = (HyperLink)e.Item.FindControl("hyp_Edit");
            HiddenField hf_id=(HiddenField )e.Item .FindControl ("hf_id");
            tbLoaiSP loaisp = (tbLoaiSP)e.Item.DataItem;
            lit_Ma.Text = loaisp.IdLoaiSP.ToString ();
            hyp_TenLoai.Text = loaisp.TenLoai;
            hyp_Edit.NavigateUrl = "LoaiSpEdit.aspx?id=?" + loaisp.IdLoaiSP.ToString();
            hf_id.Value = loaisp.IdLoaiSP.ToString();           
        }
    }

    protected void lbt_Delete_Click(object sender, EventArgs e)
    {
        foreach (RepeaterItem item in this.Repeater1.Items)
        {
            CheckBox chk = (CheckBox)item.FindControl("cb_xoa");
            if (chk.Checked == true)
            {
                HiddenField hf_id = (HiddenField)item.FindControl("hf_id");
                tbLoaiSPBUS.delete(int.Parse(hf_id.Value));
            }
        }
        load_data();
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        PagerV2_8_1.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        load_data();
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        load_data();
    }
}
